﻿using System.Drawing.Drawing2D;
using System.Drawing.Text;
namespace LeRenard.Libraries.Drawing.GdiPlus.Forms
{
    internal static class GraphicsOptimizer
    {
        /// <summary>
        /// Optimizes a <see cref="Graphics"/> <see cref="Buffer"/> for GDI+ drawing.
        /// </summary>
        /// <param name="buffer">The buffer to be optimized.</param>
        public static void OptimizeBuffer(IBuffer buffer)
        {
            // See http://www.codeproject.com/Articles/409988/Beginners-Starting-a-2D-Game-with-GDIplus

            buffer.Graphics.SmoothingMode = SmoothingMode.HighQuality;
            buffer.Graphics.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;

            buffer.Graphics.CompositingMode = CompositingMode.SourceOver;
            buffer.Graphics.CompositingQuality = CompositingQuality.HighSpeed;
            buffer.Graphics.PixelOffsetMode = PixelOffsetMode.Half;
        }

        /// <summary>
        /// Optimizes a <see cref="Graphics"/> target for GDI+ drawing.
        /// </summary>
        /// <param name="graphics">The <see cref="Graphics"/> target to be optimized.</param>
        public static void OptimizeTarget(ITarget target)
        {
            // See http://www.codeproject.com/Articles/409988/Beginners-Starting-a-2D-Game-with-GDIplus

            target.Graphics.CompositingMode = CompositingMode.SourceCopy;
            target.Graphics.CompositingQuality = CompositingQuality.AssumeLinear;
            target.Graphics.SmoothingMode = SmoothingMode.None;
            target.Graphics.InterpolationMode = InterpolationMode.NearestNeighbor;
            target.Graphics.TextRenderingHint = TextRenderingHint.SystemDefault;
            target.Graphics.PixelOffsetMode = PixelOffsetMode.HighSpeed;
        }
    }
}
